﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
using _02.建造者模式.Entities;

namespace _02.建造者模式.Builders
{
    public class MealBuilder
    {
        private readonly Meal _meal;
        public MealBuilder(string mealName)
        {
            _meal = new Meal(mealName);
        }

        /// <summary>
        /// 创建必选商品
        /// </summary>
        /// <param name="products"></param>
        public void BuildRequiredProducts(List<Product> products)
        {
            products.ForEach(product =>
            {
                this._meal.MealProducts.Add(new MealProduct(true, false, 0, this._meal, product));
            });
        }

        /// <summary>
        /// 创建升级商品
        /// </summary>
        /// <param name="upGradedProducts"></param>
        public void BuildUpGradedProducts(Dictionary<Product, decimal> upGradedProducts)
        {
            foreach (KeyValuePair<Product, decimal> keyValue in upGradedProducts)
            {
                this._meal.MealProducts.Add(new MealProduct(true, true, keyValue.Value, this._meal, keyValue.Key));
            }
        }

        /// <summary>
        /// 创建推荐（可选）商品
        /// </summary>
        /// <param name="products"></param>
        public void BuildChoosableProducts(List<Product> products)
        {
            products.ForEach(product =>
            {
                this._meal.MealProducts.Add(new MealProduct(false, false, 0, this._meal, product));
            });
        }

        /// <summary>
        /// 创建套餐
        /// </summary>
        /// <returns></returns>
        public Meal Build()
        {
            return this._meal;
        }
    }
}
